package com.itcast.datasource.c3p0;

import com.mchange.v2.c3p0.ComboPooledDataSource;

import javax.sql.DataSource;
import java.sql.Connection;
import java.sql.SQLException;

/**
 * c3p0 的演示
 */
public class c3p0Demo2 {
    public static void main(String[] args) throws SQLException {
        // 获取数据库连接池对象
        DataSource ds = new ComboPooledDataSource();
        // 获取连接
        for (int i = 1; i <= 11; i++) {
            Connection connection = ds.getConnection();
            System.out.println(connection);

            if (i == 5) {
                connection.close(); // 归还连接
            }
        }
    }
}
